<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>课程列表操作管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
	function page(n,s){
		if(n) $("#pageNo").val(n);
		if(s) $("#pageSize").val(s);
		$("#searchForm").attr("action","${ctx}/fee/roomList");
		$("#searchForm").submit();
    	return false;
    }
		function back(){
			window.close();
	    }
		
		function chk(){
			$("#inputForm").submit();
        }
		
		function upload(){
			var table = document.getElementById("contentTable");
			var rows = table.rows;
			var teacheridstr = "";
			var parentteacherids = window.opener.document.getElementById("teacherids").value
			console.log("parent"+parentteacherids)
			obj = document.getElementsByName("teacherids");
			//console.log(obj[2].checked)
			for(var i=0;i<obj.length;i++){
				if(obj[i].checked){
					if(teacheridstr.length >0){
						teacheridstr+=",";
						}
					window.opener.$("#teacher").append("<p>"+rows[i].cells[1].innerHTML+"</p>");
					teacheridstr+=rows[i].cells[0].children[0].value
					
				}
			}
					
					window.opener.$("#teacherids").val(teacheridstr+","+parentteacherids)
					console.log("str"+teacheridstr)
            self.close();
		}
		
	</script>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			}); 
		});
		
		
		$(document).ready(function() {
			$("#closeWindow").click(function(){
				
				var table = document.getElementById("contentTable");
				var rows = table.rows;
				obj = document.getElementsByName("studnetid")
				
				for(var i=0;i<obj.length;i++){
					if(obj[i].checked){
						window.opener.$("teacher").val(rows[i].cells[2].innerHTML);
						window.opener.$("curUser.number").val(rows[i].cells[1].innerHTML);
						window.opener.$("curUser.username").val(rows[i].cells[2].innerHTML);
					}
				}
				
				
				
				
				
	            //self.close();
			});
		});
	</script>
</head>
<body>	

		<form:form id="searchForm"  action="" method="post" class="breadcrumb form-search ">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<sys:tableSort id="orderBy" name="orderBy" value="${page.orderBy}" callback="page();"/>
		<ul class="ul-form">
			<li class="btns" style="margin-left:200px;"><input class="btn btn-primary" type="button" value="提 交" onclick="upload()"/></li>
			<li class="btns"><input class="btn btn-primary" type="button" value="取消" onclick="back()"></li>
		</ul>
	</form:form>
	<form:hidden name="teacherids" id="teacherids" path="teacherids" value="${teacherids }"/>
	<!-- 上面的这个form其实是没有作用的   真正有作用的是JS -->
							<table id="contentTable" class="table table-striped table-bordered table-condensed">
								<thead>
									<tr>
										<th>选择</th>
										<th>用户姓名</th>
										<th>房间号</th>
									</tr>
								</thead>
								<tbody>
								<c:forEach items="${page.list}" var="a" >
									<tr>
									
										<td><form:checkbox  name="teacherids" id="teacherids" path="teacherids" value="${a.id }" class="required"/></td>
										<td>${a.user.name}</td>
										<td>${a.roomNum}</td>
									</tr>
								</c:forEach>
								</tbody>
							</table>
							
	<div class="pagination">${page}</div>	
</body>
</html>